package com.sskj.gocoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.AddressList;
import com.sskj.gocoin.m.bean.ChargeCoinItemBean;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.http.JsonCallBack;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.CashAddressAddActivity;
import com.sskj.gocoin.v.activity.CashAddressListActivity;

import java.util.List;

/**
 * Created by Administrator on 2018/4/2 0002.
 */

public class CashPresenter extends BasePresenter {

    public void requestUserAssetList() {
        OkGo.<com.sskj.common.base.HttpData<List<ChargeCoinItemBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASEET_LIST)
                .params("mobile", MyAppLication.getMobile())
                .execute(new com.sskj.lib.http.JsonCallBack<com.sskj.common.base.HttpData<List<ChargeCoinItemBean>>>() {
                    @Override
                    public void onSuccess(Response<com.sskj.common.base.HttpData<List<ChargeCoinItemBean>>> response) {
                        com.sskj.common.base.HttpData<List<ChargeCoinItemBean>> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            ((CashAddressAddActivity)mView).onDataSuccess(httpListData.getData());
                        }
                    }
                });
    }

    public void requestAddressList(int assetId) {
        if (assetId==-1){
            OkGo.<HttpData<AddressList>>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_LIST)
                    .execute(new JsonCallBack<HttpData<AddressList>>(this) {

                        @Override
                        public void _onSuccess(Response<HttpData<AddressList>> response) {
                            HttpData<AddressList> body = response.body();
                            ((CashAddressListActivity)mView).onResponseCashAddressListSuccess(body.getData());
                        }
                    });
        }else{
            OkGo.<HttpData<AddressList>>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_LIST)
                    .params("type", assetId)
                    .execute(new JsonCallBack<HttpData<AddressList>>(this) {

                        @Override
                        public void _onSuccess(Response<HttpData<AddressList>> response) {
                            HttpData<AddressList> body = response.body();
                            ((CashAddressListActivity)mView).onResponseCashAddressListSuccess(body.getData());
                        }
                    });
        }

    }

    public void requestAddAddress(String address, String notes, int type) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_ADD)
                .params("address", address)
                .params("notes", notes)
                .params("type", type)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.msg);
                        ((CashAddressAddActivity)mView).onResponseCashAddressAddSuccess();
                    }
                });
    }

    /**
     * 删除提现地址
     * @param type 0:eth ;  1: btc
     * @param position
     * @param id
     */
    public void requestDelite(int type, int position, String id) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADDRESS_DELETE)
                .params("address_id", id)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().msg);
                        ((CashAddressListActivity)mView).onDeliteSuccess(position);
                    }
                });
    }

    //验证谷歌验证码 删除地址调用
    public void requestGoogleCheck(String googleCode,int type, int position, String id) {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.GOOGLE_LOGIN)
                .params("dyGoodleCommand", googleCode)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<String>> response) {
                        HttpData<String> body = response.body();
                        if (body.getCode() == 200) {
                            ((CashAddressListActivity)mView).googleCheckSuccess(type, position, id);
                        } else {
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }

    //验证谷歌验证码 添加地址调用
    public void requestGoogleCheck(String googleCode,String address) {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.GOOGLE_LOGIN)
                .params("dyGoodleCommand", googleCode)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<String>> response) {
                        HttpData<String> body = response.body();
                        if (body.getCode() == 200) {
                            ((CashAddressAddActivity)mView).googleCheckSuccess(address);
                        } else {
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }
}
